import { Matrix } from "game-algorithm";
import { loadModule } from "./loadModule";
const exports = await loadModule("../../package/wasm/build/FloodFill.wasm");
const {
    __getArray,
    getColorFlood,
    __newArray,
    Uint32Array_ID,
    __pin,
    __unpin,
} = exports;
export const AsFloodFill = (
    m: Matrix<[number, number]>,
    X: number,
    Y: number
): number[][] => {
    console.time("flatten");
    const input = m.flat().flat();
    console.timeEnd("flatten");
    console.time("floodFill");
    let arrayPtr = __pin(__newArray(Uint32Array_ID as number, input));

    const data = (getColorFlood as any)(arrayPtr, X, Y, m.width, m.height);
    const result = __getArray(data).map((i) => __getArray(i));
    __unpin(arrayPtr);
    console.timeEnd("floodFill");
    return result;
};
